﻿package org.aquiferserver.client.flex 
{
	import flash.net.Socket;
	import org.aquiferserver.common.AquiferMessage;
	
	/**
	 * ...
	 * @author Seth Albanese
	 */
	public class AquiferSocket extends Socket
	{
		public function writeMessage( msg:AquiferMessage )
		{
			var serializedMsg:String = SerializationCodec.serialize( msg );
			this.writeUTFBytes ( serializedMsg );			
			this.writeByte( 0x00 );
			this.flush();
		}
		
		public function readMessage() : AquiferMessage
		{
			var resp:String = this.readUTFBytes( this.bytesAvailable );					
			return SerializationCodec.deserialize( resp.replace( /^\s+|\s+$/g, '' ) );
		}
	}
	
}